<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%><%@ include file="pub/top.jsp"%>
<%@ page import="java.util.List,java.util.Map,com.servlet.My,com.servlet.M"%>
<!-- 全局变量 函数定义区 -->
<%!%>
<!-- 实例变量 函数定义区 -->
<%
	//网页title
	String JSPTITLE = "权限管理";
%>
<%@ include file="pub/head.jsp"%>
<!-- 样式添加区 -->
<link rel="stylesheet" href="<%=basePath%>DataTables/datatables.min.css">
<!-- 下右内容区 -->

<div id="modal-tree-ck" class="modal bs-example-modal-sm" tabindex="-1"
	role="dialog" aria-labelledby="mySmallModalLabel">
	<div class="modal-dialog   width-90" role="document"  >
		<div class="modal-content">
			<div class="modal-header">
				<label> <input
					class="ace ace-switch ace-switch-3 tree-checkall" type="checkbox">
					<span class="lbl  width-100 "></span>
				</label>
				<a class="close" data-dismiss="modal">x</a>
				
				
			</div>
			<div class="modal-body" style="overflow-x:hidden;overflow-y:auto;">
			<div id="tree" class="  width-100 "></div>
			
			</div>
			<div class="modal-footer">
				<input type="text" id="tijiao" style="display: none"> 
					<button class="btn btn-danger btn-block pull-right"  id="tjbd">
						<i class="ace-icon fa fa-check bigger-110 green  "></i> 提交
					</button> 
			</div>
		</div>
		
	</div>
</div>

<div class="main-content-inner">
	<div class="breadcrumbs ace-save-state" id="breadcrumbs">
		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i> 系统</li>
			<li class="active"><%=JSPTITLE%></li>
		</ul>
	</div>
	<div class="page-content">
		<!-- page-header{ -->
		<div class="page-header">
			<!-- table header1{ -->
			<div class="row">
				<div class="col-xs-12">
					<div class="clearfix">
						<div class="pull-right tableTools-container"></div>
						<div class="">
							<div class="btn-group" style="margin-top: 5px">
								<a href="#" class="btn-refresh btn  btn-xs "> <i
									class="im-spinner10 fa-spin"></i> 刷新
								</a>
								
							</div>
						</div>
					</div>
					<div id="demo" class="panel-collapse collapse ">
						<div class="panel-body well">
							<form>
								<div class="col-lg-6 col-sm-6 ">
									<div class="col-lg-12 col-sm-12  input-group ">
										<span class="input-group-addon"> <i
											class="fa fa-calendar"></i>
										</span> <input type="text" name="start" placeholder="2014-11-17"
											class="input-sm form-control" /> <span
											class="input-group-addon">到</span> <input type="text"
											class="input-sm form-control" name="end" value=""
											placeholder="2014-11-17" />
									</div>
								</div>
								<div class="col-lg-3 col-sm-3">
									<input type="text" class="input-sm  form-control"
										placeholder="标题" id="searchtxt">
								</div>
								<div class="col-lg-12 col-sm-12">
									<button type="button"
										class="btn btn-success btn-sm  pull-right">
										<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
										查找
									</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			<!-- }table -header1  -->
		</div>
		<!-- }page-header  -->

		<!-- table header2{ -->
		<div class="row">
			<div class="col-xs-9 tablehead2L"></div>
			<div class="col-xs-3 tablehead2R"></div>
		</div>
		<!-- }table -header2  -->
		<!--  table { -->
		<div class="row tablexscroll" >
				<table id="myTable" class="table table-striped table-bordered" cellspacing="0"  >
					<thead>
						<tr>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
			
		</div>
		<!--}table  -->
		<!-- table end{ -->
		<div class="row">
			<div class="col-xs-4"></div>
			<div class="col-xs-8">
				<ul class="pagination"></ul>
				<span class="tablefooterinfo"></span>
			</div>
		</div>
		<!--}table end -->
	</div>
</div>
<!--  footer{ -->
<div class="footer">
	<div class="footer-inner">
		<div class="footer-content  pull_right">
			<span class="bigger-110"> <span class="blue bolder"></span>
			</span>
		</div>
	</div>
</div>
<!--}  footer -->

<a href="#" id="btn-scroll-up"
	class="btn-scroll-up btn btn-sm btn-inverse"> <i
	class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>

<%@ include file="pub/bottom.jsp"%>
<!-- 引入组件库 -->
<script src="<%=basePath%>DataTables/datatables.min.js"></script>
<script src="<%=basePath%>js/hyl.page.js"></script>
<link rel="stylesheet" href="../css/bootstrap-treeview.min.css" />
<script src="../js/bootstrap-treeview.min.js"></script>
<!-- 自定义脚本 加载区 -->
<script>
jQuery(function($){
	$(document).on('click', '.bt-cakan', function(e){
		//var selects=  '代理商用户管理催收分配催收处理管理员权限管理员记录';
		$tree.treeview('uncheckAll');
		  checkedTreeitem($tree, this.dataset.manage);
		  $('#tijiao').val($(this).data('id'));
        $("#modal-tree-ck").modal("show");
        e.stopPropagation();//防止冒泡
    });
	
	$(document).on('click', '#tjbd', function(e){
		var id=$('#tijiao').val();
		var SZ="";
			//console.log($tree.treeview('getCollapsed'));
			var data=$tree.treeview('getCollapsed');
			for(var i in data){
				//console.log(data[i].state.checked)
				if(data[i].state.checked){
					SZ=SZ+data[i].text+",";
				}
			}
		//console.log(SZ);
		$.ajax({
			type : 'post',
			url : 'Dao/SqlDao.jsp',
			data:{'id':id,'data':SZ,'state':2},
			success : function(data) {
				//console.log(data)
				alert("成功");
				window.location.reload();
			}
		});
	});

	function getTreeitems(array){
		  var b = [];
		  for ( var i in array) {
		    b.push({
		      text : array[i]
		    })
		  }
		  return b;
		}
		function checkedTreeitem(treeobj,sel){
		  var collapsedNodes = treeobj.treeview('getCollapsed');
		  if ($.isArray(sel)) {			  
			  selects=sel;
		  }else {
			  selects=sel.split(",");
		  }
		    for ( var j in collapsedNodes) {
		      for ( var i in selects) {
		        if (collapsedNodes[j].text == selects[i]) {
		          $tree.treeview('checkNode', collapsedNodes[j].nodeId);
		          break;
		        }
		      }
		    }		
		}

		 function getTree(){
		  var tree = getTreeitems([
		      '用户管理','第三方应用管理','系统设置'
		  ]);
		  var nds0 = getTreeitems([
			  '注册用户','用户管理'
		  ]);
		  var nds1 = getTreeitems([
			  '应用管理','切到子系统','关联账号','更新应用','关联用户'
		  ]);
		  var nds2 = getTreeitems([
			 '修改密码','权限管理','设置'
		  ]);
		  
		  // alert(tree) 
		  tree[0].nodes = nds0;
		  tree[1].nodes = nds1;
		  tree[2].nodes = nds2;
		  //console.log(JSON.stringify(tree))
		  return tree;
		}
		var $tree = $('#tree').treeview({
		  data : getTree(), // data is not optional
		  icon : "glyphicon glyphicon-stop",
		  showCheckbox : true,
		  icon : "glyphicon glyphicon-stop"
		});
	
	$(document).on('click', '.tree-checkall', function(){
        var flag = $(this).prop("checked");
        if (flag)
          $tree.treeview('checkAll');
        else
          $tree.treeview('uncheckAll');
      });
})


  var BASEPATH="<%=basePath%>";
  $(document).ready(function() {
    var table = $('#myTable').DataTable({
      dom : '',
      renderer : "bootstrap",
      paging : false,
      "ordering" : false,
      "searching" : false,
      "info" : false,
      buttons : [
          'colvis', 'pdf', {
            text : 'My button',
            action : function(dt) {
              console.log('My custom button!');
            }
          }
      ],
      //stateSave: true, 
 	  "language" : {
        "lengthMenu" : "每页 _MENU_ 条记录",
        "zeroRecords" : "没有找到记录",
        "info" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
        "infoEmpty" : "无记录",
        "infoFiltered" : "(从 _MAX_ 条记录过滤)"
      //, "decimal": ".", "thousands": "," ,
      },	 
      //列属性声明
      
      //render特定列

// e.id 0,1 e.ctime,2e.etime,3e.ftime,4e.uid,5e.title,6e.replyid,7e.state,8e.ualias,9e.i0,10e.i1
      "columnDefs" : [ 
        { title : "操作",
          "render" : function(data, type, row) {
            return  '<button class="btn btn-sm btn-success btn-white btn-round bt-cakan" data-manage="'+row[3]+'" data-id="'+row[0]+'"> <i class="ace-icon fa fa-check bigger-110 green"></i> 查看权限</button>' ;
          },
          "targets" : 0
        },
        {   title : "角色名称",
          "render" : function(data, type, row) {
            return  row[2] ;
          },
          "targets" : 1
        },{
            title : "用户数",
            "render" : function(data, type, row) {
              return row[1];
            },
            "targets" : 2
        }
      ],
      "footerCallback" : function(row, data, start, end, display) {
        //汇总统计回调函数
        
      }
    });
    
    //自定义的分页的函数,名字不要改 确保与page.js中的调用函数名一致;
    //载入数据的函数
    //传入第几页
    var PG = HylPage.getInstance("<%=JSPTITLE%>");
    PG.load = function(n) {
      var  pgindex= PG.sessionPgIndex();//缓存成上一次定位的页
      if (pgindex&&(!n))
        n=pgindex;
      else if((!pgindex)&&(!n)){
        n=1;
      }
      //需要传到后台的参数 	
      var data1 = {
        "rs_index" : (n - 1) * PG.pgSize,//从第几条记录开始
        "rs_size" : PG.getMaxRcNum()//取几条数据过来
      };
      //用法: $.post("chargelist2.do", data1).success(function(rs) {});    	
      //解释: (去哪里,要做什么) 成功做完成以后{
      // 返回以后 做什么...
      //}
      $.post("<%=basePath%>admin/Dao/member_quanxian_dao.jsp", data1).success(function(result) {
				//console.log(result);
				PG.bind({
				tableobj : table,
				pageobj : $(".pagination"),
				rs : result.BODY._rs,
				pindex : n,
				psize : 0
			});
			if (result.BODY.total&& result.BODY.total > 0)
					$(".tablefooterinfo").html("一共查询到"+ result.BODY.total+ "条记录");});
			}
			PG.load();
						//行点击事件
						$('#myTable tbody').on('click', '.btn-del', function() {
							var qtr = $(this).parent('tr');
							var data = table.row(qtr.get(0)).data();
							//alert('You clicked on ' + data[0] + '\'s row');
						});
						$('#myTable tbody').on('click', '.btn-chg', function() {
							var qtr = $(this).parent('tr');
							var data = table.row(qtr.get(0)).data();
							//alert('You clicked on ' + data[0] + '\'s row');
						});
					});
</script>
